package com.md.common.utils.excel;

import com.md.common.utils.excel.model.ExcelCell;
import com.md.common.utils.excel.model.ExcelCellData;
import com.md.common.utils.excel.model.ExcelSheet;
import org.apache.commons.lang3.ObjectUtils;

import java.io.File;
import java.util.List;

public abstract class AbstractExcelHandler implements ExcelHandler {

	@Override
	public List<List<ExcelCellData>> readExcel(String excelPath, boolean hasTitle, int colCount) {
		return readExcel(excelPath, hasTitle, 0, colCount);
	}

	@Override
	public List<List<ExcelCellData>> readExcel(String excelPath, boolean hasTitle, int sheetNo, int colCount) {
		return readExcel(new File(excelPath), hasTitle, sheetNo, colCount);
	}

	@Override
	public List<List<ExcelCellData>> readExcel(File excel, boolean hasTitle, int colCount) {
		return readExcel(excel, hasTitle, 0, colCount);
	}

	@Override
	public List<List<ExcelCellData>> readExcel(File excel, boolean hasTitle, int sheetNo, int colCount) {
		return readExcel(excel, hasTitle ? 1 : 0, sheetNo, colCount);
	}

	@Override
	public abstract List<List<ExcelCellData>> readExcel(File excel, int ignoreRow, int sheetNo, int colCount);

	@Override
	public File writeExcel(String filePath, ExcelSheet sheet) {
		return writeExcel(filePath, sheet.getMainTitles(), sheet.getTitles(), sheet.getDatas(), ObjectUtils.defaultIfNull(sheet.getName(), "sheet"), sheet.getNo());
	}

	@Override
	public File writeExcel(String filePath, List<List<String>> datas) {
		return writeExcel(filePath, datas, "sheet");
	}

	@Override
	public File writeExcel(String filePath, List<List<String>> datas, String sheetName) {
		return writeExcel(filePath, null, datas, sheetName);
	}

	@Override
	public File writeExcel(String filePath, List<String> titles, List<List<String>> datas) {
		return writeExcel(filePath, titles, datas, "sheet");
	}

	@Override
	public File writeExcel(String filePath, List<String> titles, List<List<String>> datas, String sheetName) {
		return writeExcel(filePath, titles, datas, sheetName, 0);
	}

	@Override
	public File writeExcel(String filePath, List<List<String>> datas, String sheetName, int sheetNo) {
		return writeExcel(filePath, null, datas, sheetName, sheetNo);
	}

	@Override
	public File writeExcel(String filePath, List<ExcelCell> mainTitles, List<String> titles, List<List<String>> datas,
						   String sheetName) {
		return writeExcel(filePath, mainTitles, titles, datas, sheetName, 0);
	}
	
}